<PageHeader as |p|>
  <p.top>
    <nav class="breadcrumb">
      <li>
        <LinkTo @route="vault.cluster.policies" @model={{policyType}} data-test-policy-list-link={{true}}>
          <span class="sep">&#x0002f;</span>
          {{uppercase policyType}} policies
        </LinkTo>
      </li>
    </nav>
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3" data-test-policy-name="true">
      {{model.id}}
      {{#if model.enforcementLevel}}
        <span class="tag" aria-label="Enforcement level: {{model.enforcementLevel}}">
          {{model.enforcementLevel}}
        </span>
      {{/if}}
    </h1>
  </p.levelLeft>
</PageHeader>
<Toolbar>
  <ToolbarActions>
    <ToolbarDownloadButton
      @actionText="Download policy"
      @extension={{if (eq policyType "acl") model.format "sentinel"}}
      @filename={{model.name}}
      @data={{model.policy}}
    />
    {{#if (and (not-eq model.id "root") (or capabilities.canUpdate capabilities.canDelete))}}
      <ToolbarLink
        @params={{array 'vault.cluster.policy.edit' model.id}}
        @data-test-policy-edit-toggle=true
      >
        Edit policy
      </ToolbarLink>
    {{/if}}
  </ToolbarActions>
</Toolbar>
<div class="box is-bottomless is-fullwidth is-marginless">
  <div class="field">
    <JsonEditor
      @title="Policy"
      @subTitle={{if (eq policyType "acl") (concat uppercase model.format " format")}}
      @value={{model.policy}} 
      @options={{hash
        readOnly=true
        mode='ruby'
      }} />
  </div>
  {{#if model.paths}}
    <div class="field box is-shadowless no-bottom-padding is-marginless">
      <h2 class="title is-6">Paths</h2>
      <ul data-test-egp-paths>
        {{#each model.paths as |path|}}
          <li class="box has-slim-padding no-top-shadow is-marginless">
            <code class="has-text-black">{{path}}</code>
          </li>
        {{/each}}
      </ul>
    </div>
  {{/if}}
</div>
